package com.huike.clues.service.impl;


import com.huike.clues.domain.dto.ClueTrackRecordDto;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;

    @Override
    public Boolean addClueRecord(ClueTrackRecordDto clueTrackRecordDto) {
        //获取用户名
        String username = SecurityUtils.getUsername();
        //将用户名放入bean中
        clueTrackRecordDto.setCreateBy(username);
        clueTrackRecordDto.setUpdateBy(username);
        //添加线索跟进
        int clueTrackRecord = tbClueTrackRecordMapper.addClueRecord(clueTrackRecordDto);

        int clue = tbClueMapper.updateClue(clueTrackRecordDto);

        return clueTrackRecord>0 && clue>0;
    }

    @Override
    public List<ClueTrackRecordDto> queryClueRecordList(Long clueId) {
        return tbClueTrackRecordMapper.queryClueRecordList(clueId);
    }
}
